package com.hikvision.hrms.controller;

import com.hikvision.hrms.model.Position;
import com.hikvision.hrms.service.PositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author : yangliu449
 * @date :  2019/2/22
 */
@Controller
public class PositionController {

    @Autowired
    PositionService positionService;

    int total;
    //    显示部门页面
    @RequestMapping("/positionShow")
    @ResponseBody
    public ModelAndView departmentShow(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("page/position");
        return modelAndView;
    }

    @RequestMapping("/findPositions")
    @ResponseBody
    public List<Position> findPositions(){
        List<Position> list = positionService.positionData();
        System.out.println(list);
        total = list.size()+1;
        return list;
    }

    @RequestMapping("/addPosition")
    @ResponseBody
    public  void addPosition(@RequestParam(value = "id") String id, @RequestParam(value = "name") String name, @RequestParam(value = "description") String description){
        Position position = new Position();
        position.setId(total);
        position.setName(name);
        position.setDescription(description);
        positionService.addPosition(position);
    }
    @RequestMapping("/updatePosition")
    @ResponseBody
    public  void  updatePossition(@RequestParam(value = "id") Integer id, @RequestParam(value = "name") String name, @RequestParam(value = "description") String description){
        Position position = new Position();
        position.setId(id);
        position.setName(name);
        position.setDescription(description);
        positionService.updatePosition(position);
    }

    @RequestMapping("/deletePosition")
    @ResponseBody
    public  void  deletePosition(@RequestParam(value = "id") Integer id, @RequestParam(value = "name") String name, @RequestParam(value = "description") String description){
        positionService.deletePosition(id);
    }

}
